package com.pro.common.api.user.task.model.db;

import com.baomidou.mybatisplus.annotation.TableField;
import com.pro.common.api.model.BaseUserIdModel;
import com.pro.common.api.model.auth.IUserRecordClass;
import com.pro.common.api.model.auth.subaccount.IOpenSubQuery;
import com.pro.common.api.user.task.enums.EnumUserTaskStatus;
import com.pro.common.api.user.task.model.base.IUserTaskStepNotify;
import com.pro.framework.javatodb.annotation.JTDField;
import com.pro.framework.javatodb.annotation.JTDTable;
import com.pro.framework.javatodb.constant.JTDConst;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.time.LocalDateTime;
import java.util.List;

@Data
@Schema(description = "用户任务每个步骤")
@JTDTable(entityId = 20001, sequences = {
        "UNIQUE KEY `uk_taskId_stepOrder` (`task_id`,`step_order`)",
        "KEY `idx_taskId` (`task_id`)",
        "KEY `idx_status` (`status`)",
})
public class UserTaskStep extends BaseUserIdModel implements IUserRecordClass, IUserTaskStepNotify, IOpenSubQuery {

    @Schema(description = "任务ID")
    private Long taskId;

    /**
     * 步骤 枚举
     * ${@link com.pro.baoyi.api.content.process.enums.EnumContentProcessStepImageStitching}  SKU拼图任务
     */
    @Schema(description = "第几步")
    private Integer stepOrder;

    @Schema(description = "处理类型")
    private String taskType;

    @Schema(description = "步骤名称")
    private String stepName;

    @Schema(description = "执行服务名称")
    private String serviceName;

    @Schema(description = "处理状态")
    @JTDField(type = JTDConst.EnumFieldType.int_, defaultValue = "0", entityClassKey = "value")
    private EnumUserTaskStatus status;

//    @Schema(description = "步骤重试次数")
//    private Integer retryCount;

//    @Schema(description = "计划执行时间")
//    private LocalDateTime scheduledAt;

    @Schema(description = "开始时间")
    private LocalDateTime startedTime;

    @Schema(description = "完成时间")
    private LocalDateTime finishedTime;

    @Schema(description = "步骤输入信息(JSON)，可存上一步输出或任务全局参数")
    @JTDField(type = JTDConst.EnumFieldType.text)
    private String inputInfo;

    @Schema(description = "步骤输出信息(JSON)，用于生成下一步的初始输入")
    @JTDField(type = JTDConst.EnumFieldType.text)
    private String outputInfo;

    @Schema(description = "失败原因")
    @JTDField(mainLength = 500)
    private String errorMsg;

    @Schema(description = "下级用户Id")
    private Long createBy;

    @Schema(description = "步骤")
    @TableField(exist = false)
    private List<UserTaskStepCall> userTaskStepCalls;


    @Schema(description = "下一个步骤")
    @TableField(exist = false)
    private UserTaskStep nextStep;

    @Schema(description = "对应的任务")
    @TableField(exist = false)
    private UserTask userTask;

    @Schema(description = "是否结束")
    @TableField(exist = false)
    private Boolean endFlag;

    @Schema(description = "上一次同步最后一行数据的游标Id")
    @TableField(exist = false)
    private Long cursor;

    @Schema(description = "一页多少个")
    @TableField(exist = false)
    private Integer limit;
}
